package com.blank;

import com.blank.pojo.bo.User;
import com.blank.service.BookService;
import com.blank.service.Impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author BLANK
 * @date 2020/11/16
 */
@WebServlet( "/BorrowBookServlet")
public class BorrowBookServlet extends HttpServlet {
    private BookService bookService=new BookServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    int id=Integer.parseInt(request.getParameter("id"));
    String username= ((User) request.getSession().getAttribute("user")).getUsername();
        try {
           boolean b = bookService.borrowBook(id,username);
           if (b){
               response.getWriter().write("success");
           }else {
               response.getWriter().write("fail");
           }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }


}
